/*
 *     Copyright (c) 2021. cc01cc. All rights reserved.
 *
 *     This file is part of this file.
 *
 *     This file is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Affero General Public License as published
 *     by the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This file is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Affero General Public License for more details.
 *
 *     You should have received a copy of the GNU Affero General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include <stdio.h>
#include <stdlib.h>

int main()
{
    // struct Triangle
    // {
    //     int x;
    //     int y;
    //     int path[100];
    // };
    // typedef struct Triangle Triangle;
    // Triangle triangle[100];

//    the number of line.
    int n_line = 0;
    int triangle[100][100] = {0};
    int store_path[100] = {0};
    int i, j, i_store_path;
    scanf("%d", &n_line);
    freopen("tower.txt", "r", stdin);

    scanf("%d", &n_line);
    freopen("tower.txt", "r", stdin);


    for(i = 0; i < n_line; i++)
    {
        for(j = 0; j < i + 1; j++)
        {
            scanf("%d", &triangle[i][j]);
        }
    }
    if(n_line == 0) return 0;
    for(i = n_line-2, j = 0, i_store_path = 0; i >= 0; i--)
    {
        for(j = 0; j < i+1; j ++)
        {
            if(triangle[i][j] + triangle[i+1][j] < triangle[i][j] + triangle[i+1][j+1])
            {
                triangle[i][j] = triangle[i][j] + triangle[i+1][j+1];
            }else
            {
                triangle[i][j] = triangle[i][j] + triangle[i+1][j];
            }
        }
    }
    return 0;
}

